跳到主要内容

NPM 包安装策略

1 分钟阅读

概述

在 npm 中,"安装策略"(Installation Strategy)是指用于解析和管理包的依赖项的方法和规则。

开始

install-strategy

  • 默认值:"hoisted"

    Default: "hoisted"

  • 类型:"hoisted"、"nested"、"shallow" 或 "linked"

    Type: "hoisted", "nested", "shallow", or "linked"

设置在 node_modules 中安装包的策略。提升(默认):在顶层安装非复制,并在目录结构中根据需要复制。嵌套:(以前的 --legacy-bundling)安装到位,无需吊装。浅层(以前的 --global-style)只在顶层安装直接的 deps。链接:(实验性)安装在 node_modules/.store 中,链接到位,未提升。

Sets the strategy for installing packages in node_modules. hoisted (default): Install non-duplicated in top-level, and duplicated as necessary within directory structure. nested: (formerly --legacy-bundling) install in place, no hoisting. shallow (formerly --global-style) only install direct deps at top-level. linked: (experimental) install in node_modules/.store, link in place, unhoisted.

简单示例

npm install --install-strategy=shallow <package-name>

通过这个指令 npm 使用浅层安装策略,类似于以前的 global-style 选项的行为。它可以将指定包以及它的所有依赖放到同一个文件夹内,而不是平铺在 node_modules 中。

评论
0条评论

添加新评论

昵称
邮箱
网址